#!/bin/bash
# set -e

TOOL_PATH=`readlink -f $0`
TOOL_PATH=`dirname $TOOL_PATH`

# parameter check
if [ $# -ne 2 ];then
	echo "$0 param num wrong!!!"
	exit 1
fi

AUTOR_GENERATER_PATH=$1
VERSION_INI=$2

if [ ! -f $VERSION_INI ]; then
	echo "$VERSION_INI not exist!!!"
	exit 1
fi

if [ ! -d $AUTOR_GENERATER_PATH ];then
    mkdir $AUTOR_GENERATER_PATH
fi

# source inport
source $TOOL_PATH/version_info.rc

# version info generate
VERSION_GENERATER=$AUTOR_GENERATER_PATH/wl_version.h
echo "####generate wl_version.h####"
wl_version_h_write $VERSION_INI $VERSION_GENERATER
echo "#############################"

# let is_need_generate=1
# TEMP_INI_GENERATER=$AUTOR_GENERATER_PATH/$WL_TEMP_VERSION_INI_NAME
# let version_ini_time=`stat $VERSION_INI  |grep  -i Change | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}'`
# let version_ini_time=`stat $VERSION_INI  |grep  -i Change | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}'`
# echo version_ini_time=$version_ini_time
# if [ ! -d $AUTOR_GENERATER_PATH ];then
#     mkdir $AUTOR_GENERATER_PATH
# else
#     if [ -f $VERSION_GENERATER ];then
#         if [ -f $TEMP_INI_GENERATER ];then
#             version_ini_md5=`md5sum $VERSION_INI | awk '{print $1}'`
#             temp_ini_md5=`md5sum $TEMP_INI_GENERATER | awk '{print $1}'`
#             if [ $temp_ini_md5 == $version_ini_md5 ];then
#                 let is_need_generate=0
#             else
#                 rm $TEMP_INI_GENERATER
#                 rm $VERSION_GENERATER
#             fi
#         else
#             rm $VERSION_GENERATER
#         fi
#     fi
# fi
# if [ $is_need_generate -ne 0 ];then
#     echo "####generate wl_version.h####"
#     wl_version_h_write $VERSION_INI $VERSION_GENERATER
# else
#     # wl_version_info_update  $VERSION_INI
#     echo "####use old wl_version.h####" 
# fi